OneShotController ... hard to explain but very useful ...

part of wslib

Inherits from: SimpleController

OneShotController performs an action only once at a change message from its Model. It is used to create the option of actions performed at a change of an object, such as a Synth being started or freed. This helpfile will not explain how this works, but instead show a number of wslib methods that use it.

see also: Server-Command-Reference, NodeWatcher

Synth:startAction_ ( action )

Listens to the Server and reacts by evaluating the function when the synth is really started

action - a Function to be evaluated. The arguments are: synth, change message (\n_go)

a = Synth( "default" ).startAction_( { |...args| ("started" + args).postln; } );

a.free;

// Synth.sched is a method from wslib-shortcuts

Synth.sched( 0.5, "default" ).startAction_( { |synth, msg| { 2.wait; synth.release; }.fork } );

Synth:freeAction_ ( action )

Listens to the Server and reacts by evaluating the function when the synth is really started

action - a Function to be evaluated. The arguments are: synth, change message (\n_end)

a = Synth( "default" ).freeAction_( { |...args| ("freed" + args).postln; } );

a.free; // or press cmd-period

Synth:pauseAction_ ( action, oneShot ), Synth:runAction_ ( action, oneShot )

Evaluates the action when a synth is paused or unpaused.

action - a Function to be evaluated. The arguments are: synth, change message (\n_on, \n_off)

oneShot - a Boolean for setting wether the function should only be evaluated once or multiple times

default : false

Object:doOnChange ( what, action, oneShot )

all methods provided above make use of this internally. I'm not sure what SuperCollider objects currently make use of the Model/dependants interface, but this method will work for all of those.

what - the change message. The type of message call the function for

action - a Function to be evaluated. The arguments are: object, change message

oneShot - a Boolean for setting wether the function should only be evaluated once or multiple times

default : true

(

a = Synth( "default" );

a.register;

a.doOnChange( \n_end, { |object, msg| [ object, msg ].postln }, true );

)

a.free; // performs the action after NodeWatcher called .changed( \n_end )